package com.whccb.apps.office.document.event.receive;

import com.actionsoft.bpms.bo.engine.BO;
import com.actionsoft.bpms.bpmn.constant.CallActivityDefinitionConst;
import com.actionsoft.bpms.bpmn.engine.core.delegate.ProcessExecutionContext;
import com.actionsoft.bpms.bpmn.engine.core.delegate.TaskBehaviorContext;
import com.actionsoft.bpms.bpmn.engine.listener.ExecuteListener;
import com.actionsoft.sdk.local.SDK;

public class SubProcessBeforeStartupEvent extends ExecuteListener {

	public String getDescription() {
		return "收文办理子流程启动前，初始化子流程相关数据。";
	}

	public String getProvider() {
		return "ActionSoft";
	}

	public String getVersion() {
		return "AWS 6.0";
	}

	@Override
	public void execute(ProcessExecutionContext pec) throws Exception {
		String parentBindid = pec.getProcessInstance().getId();
		TaskBehaviorContext callActivityCtx = (TaskBehaviorContext) pec
				.getParameter(CallActivityDefinitionConst.PARAM_CALLACTIVITY_CONTEXT);
		String subBindid = callActivityCtx.getProcessInstance().getId();

		BO parentBo = SDK.getBOAPI().getByProcess("BO_WHBK_OD_RECEIVE",
				parentBindid);

		BO subBo = SDK.getBOAPI().getByProcess("BO_WHBK_OD_RECEIVE_DO",
				subBindid);
		if (parentBo != null && subBo == null) {
			SDK.getBOAPI().query("BO_WHBK_OD_RECEIVE", true)
					.addQuery("BINDID =", parentBindid)
					.copyTo("BO_WHBK_OD_RECEIVE_DO", subBindid)
					.addNewData("DOFILE", "").exec();
		}
		subBo = SDK.getBOAPI().getByProcess("BO_WHBK_OD_RECEIVE_DO", subBindid);
		// 构建父流程的签批DC，将其复制到子流程相应位置。
		String parentDCGroupValue = parentBindid;
		String parentDCFileValue = parentBo.getId();
		String subDCGroupValue = subBindid;
		String subDCFileValue = subBo.getId();

		// PB由手写签批改为多行，故而此处注释掉

	}
}
